package logic

import (
	"context"
	"work-safety/workrpc/workrpc"

	"work-safety/api/internal/svc"
	"work-safety/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductUpdataLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductUpdataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductUpdataLogic {
	return &ProductUpdataLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductUpdataLogic) ProductUpdata(req *types.ProductUpdataRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	data, err := l.svcCtx.WorkRpc.ProductUpData(l.ctx, &workrpc.ProductUpDataRequest{
		Title:        req.Title,
		Price:        float32(req.Price),
		Address:      req.Address,
		ProductImage: req.ProductImage,
		UserId:       req.UserId,
		ProductId:    req.ProductId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "修改成功成功",
		Data:    data,
		Code:    200,
	}, nil

}
